﻿<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>

<tiles:insertTemplate template="LayoutAdmin.jsp">
	<tiles:putAttribute name="body">
		<!-- LEFT -->
		<div class="art-layout-cell art-content clearfix">
			<div class="art-block clearfix">
				<div class="art-blockcontent">
					<form action="crudProduct.do" method="get"><input type="submit" name="btnRefresh" value="Refresh" class="art-button"></form>
					Status: <h4 style="color: red">${error}</h4>
					<form action="crudProduct.do?categoryId=${entityCategory.id!=null?entityCategory.id:1 } " method="post">
						<p>Id: <input name="txtId" value="${entityProduct.id}" readonly="readonly"></p>
						<p>Name:  <input name="txtName" value="${entityProduct.name}" required></p>
						<p>Image: <img name="inputImg" src="#" > </p>
						<p>UnitPrice: <input type="number" min="0" name="txtUnitPrice" value="${entityProduct.unitPrice}" required></p>
						<p>UnitBrief: <input name="txtUnitBrief" value="${entityProduct.unitBrief}" required></p>
						<p>Quantity: <input type="number" min="0" name="txtQuantity" value="${entityProduct.quantity}" required></p>
						<p>State: <input name="rdoState" type="radio" value="true" ${entityProduct.state?'checked':''}> Còn hàng   
									<input name="rdoState" type="radio" value="false" ${entityProduct.state?'':'checked'}> Hết hàng</p>
						<p>Category: 
							<select name="cboCategory">
							<c:forEach var="c" items="${showCategory}">
								<option  <c:choose>
											<c:when test="${c.id==entityCategory.id}"> selected="selected" </c:when> 
										</c:choose> value="${c.id}">${c.name }
								</option>	
							</c:forEach>
							</select>
						</p>
						<p>Note: <input name="txtNote" value="${entityProduct.note}"></p>
						<br><br>
						<input type="submit" name="btnCreate" value="Create" class="art-button">
						<input type="submit" name="btnUpdate" value="Update" class="art-button">
						<input type="submit" name="btnDelete" value="Delete" class="art-button">
					</form>	
					
				
					<h1>HIỂN THỊ SẢN PHẨM THEO CATEGORY</h1>
					<table class="art-article" width="80%">
						<tbody>
							<tr style="background-color: #42BEEB">
								<th>Id</th>
								<th>Name</th>
								<th>Unit Price:</th>
								<th>Unit Brief:</th>
								<th>Quantity:</th>
								<th>&nbsp;</th>
							</tr>
							
							<c:forEach var="s" items="${entityCategory.products}">
							<tr>
								<td>${s.id }</td>
								<td>${s.name }</td>
								<td>${s.unitPrice }</td>
								<td>${s.unitBrief }</td>
								<td>${s.quantity }</td>
								
								<td><a href="crudProduct.do?categoryId=${entityCategory.id }&productId=${s.id}">Chi tiết</a></td>
							</tr>
							</c:forEach>
						</tbody>
					</table>
				</div>
			</div>
		</div>
		<!-- END LEFT -->
		
		
		<!-- RIGHT -->
		<div class="art-layout-cell art-sidebar1 clearfix">
			<!-- SEACH -->
			<div class="art-block clearfix">
			    <div class="art-blockheader">
			        <h3 class="t">Search</h3>
			    </div>
			    <!-- END TIEU DE -->
			    <div class="art-blockcontent">
				    <div>
						<form action="#" class="art-search" method="get" name="searchform">
						  	<input type="text" value="" name="s">
						  	<input type="submit" value="" name="search" class="art-search-button">
						</form>
					</div>
				</div>
			</div>
			<!-- END SEACH -->
			
			<!-- CATEGORY -->
			<div class="art-block clearfix">
			    <div class="art-blockheader">
			        <h3 class="t">Categories</h3>
			    </div>
			    
				<div class="art-blockcontent">
					<div>	
						<ul>
							<c:forEach var="c" items="${showCategory}">
							<li><a href="crudProduct.do?categoryId=${c.id }">${c.name }</a></li>
							</c:forEach>
						</ul>
					</div>
				</div>
			</div>
			
			<!-- END CATEGORY -->
		
		</div>
		<!-- END RIGHT -->

	</tiles:putAttribute>
</tiles:insertTemplate>